package main

import (
	"context"
	"github.com/spf13/cobra"
	"os"
	"os/signal"
	"syscall"
	"ts-downloader/download"
	"ts-downloader/merge"
)

var rootCmd = &cobra.Command{
	Use: "ts-downloader",
	Run: nil,
}

func init() {
	rootCmd.AddCommand(download.Cmd)
	rootCmd.AddCommand(merge.Cmd)
}

func main() {
	sig := make(chan os.Signal, 1)
	signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
	ctx, cancel := context.WithCancel(context.Background())
	go func() {
		<-sig
		cancel()
	}()
	err := rootCmd.ExecuteContext(ctx)
	cobra.CheckErr(err)
}
